<?php
$cliente = new Clientes();
if (isset($_POST['cmbLista'])) {
    $codigo = $_POST['cmbLista'];
    $cliente->Carrega($codigo);
}
?>
<form name="frmRelatorio" id="frmRelatorio" method="post" action="controller/acoes_relatorio.php" target="_blank">
    <div id="divFormEmail">
        <div onclick="alteraDisplayDiv('divFormEmail');" style="float:right;position:relative;width:80px;height: 20px;background-image:url(img/fechar.png);cursor:pointer;"></div>
        <table>
            <tr>
                <td>Nome: </td>
                <td><input type="text" name="txtNomeEmail" id="txtNomeEmail" placeholder="Nome" /></td>
            </tr>
            <tr>
                <td>E-mail: </td>
                <td><input type="text" name="txtEmail" id="txtEmail" placeholder="E-mail" /></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" name="btEnviarEmail" id="btEnviarEmail" value="Enviar" /></td>
            </tr>
        </table>
    </div>
    <input type="hidden" name="hdCodCliente" id="hdCodCliente" value="<?php if (isset($_POST['cmbLista'])) { echo $cliente->getCodigo(); }?>" />
    <table class="tabela">
        <tr>
            <td class="titulo">Assessor: </td>
            <td>
                <?php
                $tipoAssessor = Util::retornaTipo("Assessor");
                if($nivel <= 1){
                    $strWhere = " AND codigo = '$logado'";
                }else if($nivel < 3){
                    $strWhere = " AND codsupervisor = '$logado'";
                }else{
                    $strWhere = "";
                }
                
                $listaAssessores = Usuarios::Lista_usuario(" WHERE codtipo = '$tipoAssessor' $strWhere ORDER BY nome ");
                ?>
                <select name="cmbAssessor" id="cmbAssessor">
                    <?php
                    foreach($listaAssessores as $lista){
                    ?>
                        <option value="<?php echo $lista->getCodigo()?>" 
                            <?php 
                                if(isset($_POST['cmbAssessor'])){
                                    if($_POST['cmbAssessor'] == $lista->getCodigo()){
                                        echo "selected=\"selected\"";
                                    }
                                }
                            ?>><?php echo $lista->getNome();?></option>
                    <?php
                    }
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="titulo">Nome Cliente: </td>
            <td>
                <input type="text" name="txtNomeCliente" id="txtNomeCliente" placeholder="Nome do Cliente" class="campo" value="<?php
                    if (isset($_POST['cmbLista'])) {
                        echo $cliente->getNome();
                    }
                    ?>" readonly="readonly" onclick="document.getElementById('btBuscar').click()" />

                    <input type="button" name="btBuscar" id="btBuscar" onclick="carregaBusca('DivPesquisaCliente', 'ajax/form_busca.php');" />
            </td>
        </tr>
        <tr>
            <td class="titulo">UF: </td>
            <td>
                <?php
                if (isset($_POST['cmbLista'])) {
                    $listaUfSelecionado = Municipios::listaUfMunicipio(" WHERE codigo = '{$cliente->getCodmunicipio()}' ");
                    foreach ($listaUfSelecionado as $lista) {
                        $uf = $lista->getUf();
                    }
                }
                $listaUF = Municipios::listaUfMunicipio(" GROUP BY uf ORDER BY uf ");
                ?>
                <select name="cmbUf" id="cmbUf" onchange="ListaMunicipios(this)">
                    <option value=""></option>
                    <?php
                    foreach ($listaUF as $key) {
                        ?>
                        <option value="<?php echo $key->getUf(); ?>" <?php
                    if (isset($uf)) {
                        if ($uf == $key->getUf()) {
                            echo "selected=\"selected\"";
                        }
                    }
                        ?>><?php echo $key->getUf(); ?></option>
                                <?php
                            }
                            ?>
                </select>
                <span id="tdRetorno" style="width: 250px;">
                <?php
                if (isset($uf)) {
                    $listaMunicipios = Municipios::listaUfMunicipio(" WHERE uf = '$uf' ORDER BY nome");
                    ?>
                    <select name="cbMunicipios" id="cbMunicipios" onchange="ListaPostosdoMunicipio(this)" style="width: 213px;">
                        <option value=""></option>
                        <?php
                        foreach ($listaMunicipios as $dados) {
                            ?>
                            <option value="<?php echo $dados->getCodigo(); ?>" <?php
                    if (isset($uf)) {
                        if ($cliente->getCodmunicipio() == $dados->getCodigo()) {
                            echo "selected=\"selected\"";
                        }
                    }
                        ?>><?php echo utf8_decode($dados->getNome()); ?></option>
                                <?php
                            }
                            ?>
                    </select>
                    <?php
                } else {
                    ?>
                    <select name="cbMunicipios" id="cbMunicipios" style="width: 213px;"></select>
                    <?php
                }
                ?>
                </span>
            </td>
        </tr>
        <tr>
            <td class="titulo">Per&iacute;odo: </td>
            <td>
                <input class="campo" type="text" name="txtDataInicial" id="txtDataInicial" size="11" maxlength="10" />
                <font style="font-size:16px;color:white;font-weight: bold;">At&eacute;</font>
                <input class="campo" type="text" name="txtDataFinal" id="txtDataFinal" size="11" maxlength="10" />
            </td>
        </tr>
        <tr>
            <td class="titulo">Bandeira</td>
            <td>
                <select name="cmbBandeira">
                    <option value=""></option>
                    <?php
                    $listaDeBandeiras = $cliente->ListaBandeira();
                    foreach($listaDeBandeiras as $bandeira){
                    ?>
                        <option value="<?php echo $bandeira;?>"><?php echo $bandeira;?></option>
                    <?php
                    }
                    ?>
                </select>
                
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" name="btBuscar" value="Listar" 
                       onclick="enviaFormComAjax('frmRelatorio','ajax/lista_visitas.php','divResultado')" />
                <input type="button" name="btBuscar" value="Ver Check-in"
                        onclick="enviaFormComAjax('frmRelatorio','ajax/lista_checkin.php','divResultado')" />
                <input type="submit" name="btImprimir" value="Imprimir" />
                <input type="reset" name="btLimpar" value="Limpar" />
            </td>
        </tr>
    </table>
    <div id="divResultado" style="clear: both; padding-left: 10px; padding-right: 10px; overflow: auto; height: 230px;" ></div>
</form>
